![]() |
PATH![]() |
When packaging your Java application JBindery assigns the default creator you specify (or '????' if you do not choose one) and assumes that all files created by the application will have the file type 'TEXT' . To override these settings, you use the setDefaultFileType and setDefaultCreator methods. Any files that your application creates will then automatically have these default values set. Listing 1-1 sets the default creator and file type and creates a file on the Mac OS.
Listing 1-1 Setting the default file type and creator
import com.apple.mrj.*;
import java.io.*;
...
public static void testFileUtils() {
/* first, set the current file and creator */
MRJOSType newType = new MRJOSType("TEXT");
MRJOSType newCreator = new MRJOSType("ttxt");
MRJFileUtils.setDefaultFileType(newType);
MRJFileUtils.setDefaultFileCreator(newCreator);
/* create a File object with the current file and creator */
File f = new File("TestFile");
if (f.exists())
f.delete();
try {
PrintStream ps = new PrintStream(new FileOutputStream(f));
ps.println("Hello, World");
ps.close();
}
catch (IOException e) {
fail("Failed to write output file", e);
return;
}
The created file TestFile has the file type 'TEXT' and the creator 'ttxt' , indicating that it is a text file and should be opened using SimpleText. Since no path was specified, TestFile appears in the default directory (typically the application's directory).